//
//  FirstHeaderCollectionReusableView.m
//  UI14_homework(礼物说发现->攻略页面)
//
//  Created by Hanlingyu on 16/8/2.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import "FirstHeaderCollectionReusableView.h"
#import "ProgramaCollectionViewCell.h"
#define kCollectionViewItemReuse @"cellReuse"
@interface FirstHeaderCollectionReusableView ()
<
    UICollectionViewDelegate,
    UICollectionViewDataSource
>

@end

@implementation FirstHeaderCollectionReusableView
- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createView];
    }
    return self;
    
}

- (void)createView {
    
    _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, CGRectGetWidth(self.frame) - 100, 40)];
//    _titleLabel.backgroundColor = [UIColor blackColor];
    [self addSubview:_titleLabel];
    _titleLabel.text = @"栏目";
    _titleLabel.font = [UIFont systemFontOfSize:14];
    _titleLabel.textColor = [UIColor lightGrayColor];
    
    _moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    _moreButton.backgroundColor = [UIColor whiteColor];
    CGFloat moreButtonWidth = 100;
    _moreButton.frame = CGRectMake(CGRectGetWidth(self.frame) - 100, 0, moreButtonWidth, 40);
    [_moreButton setTitle:@"查看全部>" forState:UIControlStateNormal];
    [_moreButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    _moreButton.titleLabel.font = [UIFont systemFontOfSize:13];
    [self addSubview:_moreButton];

    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    CGFloat itemWidth = (CGRectGetWidth(self.bounds) - 30) / 1.25;
    CGFloat itemHeight = ((CGRectGetHeight(self.bounds) - 40 - 40) / 3);
    flowLayout.itemSize = CGSizeMake(itemWidth, itemHeight);
    flowLayout.sectionInset = UIEdgeInsetsMake(5, 10, 5, 10);
    flowLayout.minimumLineSpacing = 10;
    flowLayout.minimumInteritemSpacing = 10;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    _collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 40, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds) - 40) collectionViewLayout:flowLayout];
    _collection.backgroundColor = [UIColor whiteColor];
    [self addSubview:_collection];
    _collection.dataSource = self;
    _collection.delegate = self;
    [_collection registerClass:[ProgramaCollectionViewCell class] forCellWithReuseIdentifier:kCollectionViewItemReuse];
    
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 11;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ProgramaCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier: kCollectionViewItemReuse forIndexPath:indexPath];
    return cell;
}



@end
